package com.ydd.controller.admin;

import com.ydd.dto.AdvimgDTO;
import com.ydd.dto.AdvimgPageQueryDTO;
import com.ydd.dto.AdvposPageQueryDTO;
import com.ydd.entity.YddAdvimg;
import com.ydd.mapper.YddAdvposMapper;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.YddAdvimgService;
import com.ydd.vo.AdvimgVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:46
 */
@Api(tags = "广告管理-广告图管理")
@RestController
@RequestMapping("/admin/ydd_advimg")
@Slf4j
public class YddAdvimgController {
    @Autowired
    private YddAdvimgService yddAdvimgService;


    /**
     * 广告图分页查询
     *
     * @param advimgPageQueryDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("广告图分页查询")
    public Result<PageResult> page(AdvimgPageQueryDTO advimgPageQueryDTO) {
        log.info("广告图分页查询：{}", advimgPageQueryDTO);

        //调用业务层方法，封装成pageResult数据返回
        PageResult pageResult = yddAdvimgService.page(advimgPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据ID查询广告图详情
     *
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("根据ID查询广告图详情")
    public Result selectById(String id) {
        YddAdvimg yddAdvimg = yddAdvimgService.selectById(id);
        return Result.success(yddAdvimg);
    }

    /**
     * 广告图修改
     * @param yddAdvimg
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("广告图修改")
    public Result update(@RequestBody YddAdvimg yddAdvimg){
        yddAdvimgService.update(yddAdvimg);
        return Result.success();
    }

    /**
     * 广告图添加
     * @param yddAdvimg
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("广告图添加")
    public Result add(@RequestBody YddAdvimg yddAdvimg){
        log.info("广告图添加{}",yddAdvimg);
        yddAdvimgService.add(yddAdvimg);
        return Result.success();
    }

    /**
     * 广告图删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("广告图删除")
    public Result delete(String id){
        yddAdvimgService.delete(id);
        return Result.success();
    }
}
